import request from "@/utils/request.js";


// 分页查询
export const getUserPageService = (params) => {
    return request.get('/announcement', {params: params})
}

// 批量删除
export const deleteAnnouncementsService = (ids) => {
    return request.delete('/announcement/batch', {
        data: {ids}
    });
};

// 公告列表
 export const getAnnouncementListService = () => {
     return request.get('/announcement/list');
 }

// 删除公告
export const deleteAnnouncementService = (id) => {
    return request.delete(`/announcement/${id}`);
}

// 新增公告
export const addAnnouncementService = (data) => {
    return request.post('/announcement', data);
};

// 修改公告
export const updateAnnouncementService = (data) => {
    return request.put('/announcement', data);
}

// 修改公告状态
export const updateAnnouncementStatusService = (params) => {
    const {id, status} = params;
    return request.put(`/announcement/status?id=${id}&status=${status}`);
};

// 修改公告置顶
export const updateAnnouncementTopService = (params) => {
    const {id, isTop} = params;
    return request.put(`/announcement/top?id=${id}&isTop=${isTop}`);
}

// 导出公告数据
export const exportAnnouncementDataService = async (params) => {
    const response = await request.post('/announcement/export', params, {
        responseType: 'blob'
    });
    const url = window.URL.createObjectURL(new Blob([response.data]));
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', '公告信息表.xlsx');
    document.body.appendChild(link);
    link.click();
    link.remove();
    window.URL.revokeObjectURL(url);
};